package com.saudidentalapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.saudiapp.lazylist.ImageLoader;
import com.saudiapp.webservice.Responce;
import com.saudiapp.webservice.Utilities;
import com.saudiapp.webservice.Utilities.RatingDialogListener;
import com.saudiapp.webservice.WebServiceManager;
import com.saudiapp.webservice.WebServiceManager.WebServiceListener;
import com.saudidentalapp.datamodels.Poster;

public class ActivityAboutPoster extends Activity implements OnClickListener,WebServiceListener
{
	TextView txtName,txtDescription;
	ImageView imgThumbImage,imgImage;	
	Utilities utilities;	
	ImageView imgEmail,imgRating,ximgComment;
	
	Poster poster;
	ActivityAboutPoster activity=this;
	 @Override
	protected void onCreate(Bundle savedInstanceState) 
	 {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_about_posters);			
		txtName=(TextView)findViewById(R.id.xtxtName);		
		txtDescription=(TextView)findViewById(R.id.xtxtDescription);	
		imgThumbImage=(ImageView)findViewById(R.id.ximgThumbImage);
		imgImage=(ImageView)findViewById(R.id.ximgImage);
		imgRating=(ImageView)findViewById(R.id.ximgvwRating);	
		imgRating.setOnClickListener(this);
		setView();
	}
	 
	private void setView()
	{
		utilities=Utilities.getInstance(activity);
		
		poster=(Poster) getIntent().getSerializableExtra("MyClass");
		
		txtName.setText(poster.getTitle());
	
		txtDescription.setText(poster.getDescription());
		
		ImageLoader loader= new ImageLoader(activity);
		loader.DisplayImage(poster.getThumbImage(),imgThumbImage);
		ImageLoader loader1= new ImageLoader(activity);
		loader1.DisplayImage(poster.getImage(),imgImage);	

	}

	@Override
	public void onClick(View v) 
	{
		if(v==imgRating)
		{
			utilities.showRatingDialog("Rate poster","Please rate poster",poster.getID());
			utilities.setRatingDialogListener(new RatingDialogListener() 
			{
				
				@Override
				public void OnRatingSet(float rating, int id) 
				{
					WebServiceManager webServiceManager=new WebServiceManager(activity);
					webServiceManager.setonWebServiceListener(activity);
					webServiceManager.setPosterRate(id, rating);
					
				}
				
				@Override
				public void OnRatingCancelled()
				{
					// TODO Auto-generated method stub
					
				}
			});
		}
		
	}

	@Override
	public void onProcesCompleted(int requestId, Object Data) 
	{
		utilities.dismiss();
		if(((Responce)Data).getResponceData().toString().equals("Success"))
			utilities.showToast("Thanks for rating ....");
		
	}

	@Override
	public void onErrorOccured(int requestId)
	{
		utilities.dismiss();	
		utilities.showToast("Error Occured, Please try Later...");
		
	}
}